//邮件系统数据存储

class MailData
{
    title : string;
    context : string;
    attachmentId : Array<number>;
    attachmentNum : Array<number>;
    score : number;
    time : number;
    type : number;
    status : number;        //邮件状态 -- 0、已删除（一般不出现）  1、已领取/已读  2、无附件  3、有附件
    constructor(title:string, context:string, attachmentId:Array<number>, attachmentNum:Array<number>, score:number, time:number, type:number, status:number)
    {
        this.title = title;
        this.context = context;
        this.attachmentId = attachmentId;
        this.attachmentNum = attachmentNum;
        this.score = score;
        this.time = time;
        this.type = type;
        this.status = status;
    }
}

class Mail {

    private mailList : Array<MailData>;

    Init()
    {
        this.mailList = [];
    }

    //根据服务器数据设置邮件数据
    SetMailList(data)
    {
        this.mailList = [];
        data.forEach(item => {
            let newMail : MailData = new MailData(item.title, 
                                                  item.context, 
                                                  item.attachmentId,
                                                  item.attachmentNum,
                                                  item.score,
                                                  item.time,
                                                  item.type,
                                                  item.status);
            this.mailList.push(newMail);
        });
    }

    //根据已读与否排序数据
    SortMailList()
    {
        let redMailList = [];
        let idx = 0;
        this.mailList.forEach(item => {
            if (item.status == 1)
            {
                redMailList.push(item);
                this.mailList.splice(idx, 1);
            }
            idx++;
        });
        this.mailList.concat(redMailList);
    }

    //获取邮件数据
    GetMailList()
    {
        return this.mailList;
    }
}

let MailModel : Mail = new Mail();